<?php

class FP_Controller_Action_Helper_Referer extends Zend_Controller_Action_Helper_Abstract {

    public function postDispatch()  {
	$request = $this->getRequest();
	$session = FP_Application::getSession();

// 	logdebug('FP_Controller_Action_Helper_Referer.postDispatch: Filtering http_referer for action [' . $request->getActionName() . ']');

	$norefer = $this->getActionController()->getNoRefer();
	if ($norefer && is_array($norefer)){
	    if (!in_array($request->getActionName(), $norefer)){
// 		logdebug('FP_Controller_Action_Helper_Referer.postDispatch: Remembering referer [' . $request->getRequestUri() . ']');
		$session->http_referer = $request->getRequestUri();
	    }
	} else
	    $session->http_referer = $request->getRequestUri();
    }

    public function gotoReferer($pDefaultUri=null){
	$session = FP_Application::getSession();
	$response = $this->getResponse();

	if (isset($session->http_referer))
	    $response->setRedirect('/' . ltrim($session->http_referer, '/'));
	else
	    $response->setRedirect($pDefaultUri);
    }
}

?>